package com.matrix.index.ui.home

import android.widget.RadioButton
import androidx.activity.enableEdgeToEdge
import androidx.core.view.get
import androidx.navigation.NavController
import androidx.navigation.findNavController
import com.alibaba.android.arouter.facade.annotation.Route
import com.blankj.utilcode.util.SPUtils
import com.matrix.basecore.base.BaseActivity
import com.matrix.basecore.constant.Constant
import com.matrix.index.R
import com.matrix.index.databinding.ActivityHomeBinding

@Route(path = Constant.ARouterPath.HomeActivityPath)
class HomeActivity : BaseActivity<ActivityHomeBinding>() {

    private lateinit var navController: NavController

    override fun getViewBinding(): ActivityHomeBinding {
        enableEdgeToEdge()
        return ActivityHomeBinding.inflate(layoutInflater)
    }

    override fun initView() {
//        mViewBinding.rgBtn.setOnCheckedChangeListener(object : RadioGroup.OnCheckedChangeListener {
//            override fun onCheckedChanged(p0: RadioGroup?, p1: Int) {
//
//            }
//        })
    }

    override fun initData() {
        navController = findNavController(R.id.fragment)
        (mViewBinding.rgBtn[0] as RadioButton).isChecked = true
    }

    override fun initListener() {
        mViewBinding.rgBtn.setOnCheckedChangeListener { _, _ ->
            for (i in 0 until mViewBinding.rgBtn.childCount) {
                val rb = mViewBinding.rgBtn[i] as RadioButton
                if (rb.isChecked) {
                    when (i) {
                        0 -> navController.navigate(R.id.indexFragment)
                        1 -> {
                            var isChange =
                                SPUtils.getInstance().getBoolean(Constant.Value.SP_WALLPAPER,false)
                            if (isChange) {
                                navController.navigate(R.id.animFragment)
                            } else {
                                navController.navigate(R.id.galleryFragment)
                            }
                        }
                        2 -> navController.navigate(R.id.mineFragment)
                    }
                }
            }
        }
    }
}